﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using vxi.chat.library;

namespace vxi.com.log
{
    public static class VxiLog
    {
        /// <summary>
        ///  写入\追加LOG文件
        /// </summary>
        /// <param name="path"></param>
        /// <param name="log"></param>
        public static void RecordWorkingLog(string path, string log, LogType type)
        {
            string logFileFolderPath = Path.Combine(path, "VisionChatLog");

            if (!Directory.Exists(logFileFolderPath))
            {
                Directory.CreateDirectory(logFileFolderPath);
            }
            FileInfo fi;
            switch (type)
            {
                case LogType.General:
                    {
                        fi = new FileInfo(Path.Combine(logFileFolderPath, string.Format("{0}_info.log", DateTime.Now.ToString("yyyy-MM-dd"))));
                        if (fi.Exists)
                        {
                            using (StreamWriter sw = fi.AppendText())
                            {
                                sw.Write(log + "\r\n");
                            }
                        }
                        else
                        {
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.Write(log + "\r\n");
                            }
                        }
                        break;
                    }
                case LogType.Event:
                    {
                        fi = new FileInfo(Path.Combine(logFileFolderPath, string.Format("{0}_event.log", DateTime.Now.ToString("yyyy-MM-dd"))));
                        if (fi.Exists)
                        {
                            using (StreamWriter sw = fi.AppendText())
                            {
                                sw.Write(log + "\r\n");
                            }
                        }
                        else
                        {
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.Write(log + "\r\n");
                            }
                        }
                        break;
                    }
                case LogType.Exception:
                    {
                        fi = new FileInfo(Path.Combine(logFileFolderPath, string.Format("{0}_info.log", DateTime.Now.ToString("yyyy-MM-dd"))));
                        if (fi.Exists)
                        {
                            using (StreamWriter sw = fi.AppendText())
                            {
                                sw.Write(log + "\r\n");
                            }
                        }
                        else
                        {
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.Write(log + "\r\n");
                            }
                        }
                        break;
                    }
                case LogType.Sql:
                    {
                        fi = new FileInfo(Path.Combine(logFileFolderPath, string.Format("{0}_sql.log", DateTime.Now.ToString("yyyy-MM-dd"))));
                        if (fi.Exists)
                        {
                            using (StreamWriter sw = fi.AppendText())
                            {
                                sw.Write(log + "\r\n");
                            }
                        }
                        else
                        {
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.Write(log + "\r\n");
                            }
                        }
                        break;
                    }
                default: break;
            }
        }



    }
}
